package jvlite.dao.createTable;

import java.util.HashMap;
import java.util.Map;

/**
 * organize database field mapping java type 
 * @author Administrator
 *
 */
public class Types {
	
	public static final String  VARCHAR = "VARCHAR";
	public static final String INT = "INT";
	public static final String BOOLEAN = "BOOLEAN";
	public static final String LONG = "LONG";

	// default length
	public static final int STRING_LENGTH =32;
	public static final int INT_LENGTH = 10;
	public static final int LONG_LENGTH = 10;
	
	// put all relations into a map
	public static Map<String,Integer> map = new HashMap<String, Integer>();
	static{
		map.put(VARCHAR, STRING_LENGTH);
		map.put(INT, INT_LENGTH);
		map.put(LONG, LONG_LENGTH);
		map.put(BOOLEAN, 0);
	}
	
	public static String getType(String type,int length){
		if(type == null){
			throw new RuntimeException("Not recognized the type  :"+type);
		}
		// provide type boolean
		if( length > 0){
			return type+"("+length+")";
		}
		return type;
	}
	
	public static String getString(){
		return getStirng(VARCHAR, STRING_LENGTH);
	}
	public static String getString(Integer length){
		return getStirng(VARCHAR, length);
	}
	public static String getInt(){
		return getStirng(INT, INT_LENGTH);
	}
	public static String getInt(Integer length){
		return getStirng(INT, length);
	}
	public static String getBoolean(){
		return BOOLEAN;
	}
	private static String getStirng(String str,Integer length){
		return str+"("+length+")";
	}
	public static String getLong(Integer length) {
		return getStirng(LONG, length);
	}
	public static String getLong() {
		return getStirng(LONG, LONG_LENGTH);
	}
}
